#include "dialogsyncdatabase.h"
#include "ui_dialogsyncdatabase.h"
#include "SyncDataBase/threadsyncremotedb.h"

DialogSyncDataBase::DialogSyncDataBase(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogSyncDataBase)
{
    ui->setupUi(this);
    listCheckBox.append(ui->checkBox);  listCheckBox.append(ui->checkBox_2);
    listCheckBox.append(ui->checkBox_3);    listCheckBox.append(ui->checkBox_4);
    listCheckBox.append(ui->checkBox_5);    listCheckBox.append(ui->checkBox_6);
    listCheckBox.append(ui->checkBox_7);    listCheckBox.append(ui->checkBox_8);
    listCheckBox.append(ui->checkBox_9);

    threadSyncRemoteDB=new ThreadSyncRemoteDB(this);
    connect(this,SIGNAL(sigSyncDB(QString,QString,QString,QString,QString,QString,QString,QString,QString,QStringList)),
            threadSyncRemoteDB, SIGNAL(sigSyncDB(QString,QString,QString,QString,QString,QString,QString,QString,QString,QStringList)));
    connect(threadSyncRemoteDB,SIGNAL(sigInfo(QString)),this,
            SLOT(slotInfo(QString)));
    connect(threadSyncRemoteDB,SIGNAL(sigError(QString)),this,
            SLOT(slotInfo(QString)));
    threadSyncRemoteDB->start();
}

DialogSyncDataBase::~DialogSyncDataBase()
{
    delete ui;
}

void DialogSyncDataBase::slotInfo(QString info)
{
    ui->plainTextEditInfo->appendPlainText(info);
}

void DialogSyncDataBase::on_pushButtonClose_clicked()
{
    close();
}

void DialogSyncDataBase::on_pBSync_clicked()
{
    ui->plainTextEditInfo->appendPlainText("synchronizing...");
    QStringList listTableNames;

    for(int n=0;n<listCheckBox.size();n++)
    {
        if(listCheckBox.at(n)->isChecked())
                listTableNames.append(listCheckBox.at(n)->text());
    }

    emit sigSyncDB(ui->lineEditRemoteIP->text(),ui->lineEditRemoteDBName->text(),ui->comboBoxRemoteDBMSType->currentText(),
                   ui->lineEditRemoteUserName->text(),ui->lineEditRemotePwd->text(),ui->lineEditLocalDBName->text(),
                   ui->comboBoxLocalDBMSType->currentText(),ui->lineEditLocalUserName->text(),ui->lineEditLocalPwd->text(),
                   listTableNames);

}
